package com.woniuxy.shop.Controller;

import com.hc.entity.*;
import com.woniuxy.shop.Entity.ResponseEntity;
import com.woniuxy.shop.Service.LLService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName LLcontroller
 * @Description
 * @Author ll
 * @Date 2022/10/19 15:43
 * @Version 1.0
 **/
@Transactional
@RestController
@CrossOrigin
@RequestMapping("/test")
public class LLcontroller {
    @Autowired
    LLService llService;

    @RequestMapping("/isexitshop")
    ResponseEntity isexitshop(@RequestParam("id") int id){
        ResponseEntity result = new ResponseEntity<>();
        boolean isexitshop = llService.isexitshop(id);
        result.setData(isexitshop);
        //返回值为true则该用户没有店铺
        return result;
    }

    @RequestMapping("/ispass")
    ResponseEntity ispass(@RequestParam("id") int id){
        ResponseEntity result = new ResponseEntity<>();
        boolean isexitshop = llService.ispass(id);
        result.setData(isexitshop);
        //返回值为true则该用户没有店铺
        return result;
    }
    @RequestMapping("/insertshop")
    ResponseEntity addshop(@RequestBody Shop shop){
        //后期修改从jwt中获取用户id
        shop.setUserId(1);
        llService.insertshop(shop);
        return new ResponseEntity<>("200","成功","");
    }
    @RequestMapping("/insertgoods")
    ResponseEntity addgoods(@RequestBody Goods goods){
        //后期修改从jwt中获取用户id
        //然后根据用户id查询店铺id
        goods.setShopId(5);
        llService.insertgoods(goods);
        return new ResponseEntity<>("200","成功","");

    }
    @RequestMapping("/getmygoods")
    ResponseEntity<List<Goods>> getmygoods(){
        //后续从jwt中获取店主ID
        List<Goods> getmygoods = llService.getmygoods(1);
        ResponseEntity<List<Goods>> result = new ResponseEntity<>();
        result.setData(getmygoods);
        result.setCode("200");
        result.setMsg("成功");
        return result;
    }
    @RequestMapping("/getgoodsdetail")
    ResponseEntity<Goods> getgoodsdetail(@RequestParam("id") int id){
        Goods getgoodsdetail = llService.getgoodsdetail(id);
        ResponseEntity<Goods> result = new ResponseEntity<>();
        result.setData(getgoodsdetail);
        result.setMsg("成功");
        result.setCode("200");
        return result;
    }
    @RequestMapping("/changestock")
    ResponseEntity changestock(@RequestBody Goods goods){
        llService.changestock(goods.getId(),goods.getStock()+goods.getShopId());
        ResponseEntity result=new ResponseEntity<>("200","成功","");
        return result;

    }
    @RequestMapping("/offtheshelf")
    ResponseEntity offtheshelf(@RequestParam("id") int id){
        llService.offyheshelf(id);
        ResponseEntity result=new ResponseEntity<>("200","成功","");
        return result;
    }
    @RequestMapping("/finish")
    ResponseEntity<List<Order>> finish(){
        //后续从jwt中获取id
        List<Order> finish = llService.finish(5);
        ResponseEntity<List<Order>> result=new ResponseEntity<>();
        result.setData(finish);
        result.setMsg("成功");
        result.setCode("200");
        return result;
    }
    @RequestMapping("/allorder")
    ResponseEntity<List<Order>> allorder(){
        //后续从jwt中获取id
        List<Order> finish = llService.allorder(5);
        ResponseEntity<List<Order>> result=new ResponseEntity<>();
        result.setData(finish);
        result.setMsg("成功");
        result.setCode("200");
        return result;
    }

    @RequestMapping("/notfinish")
    ResponseEntity<List<Order>> notfinish(){
        //后续从jwt中获取id
        List<Order> finish = llService.notfinish(5);
        ResponseEntity<List<Order>> result=new ResponseEntity<>();
        result.setData(finish);
        result.setMsg("成功");
        result.setCode("200");
        return result;
    }
    @RequestMapping("/addsecondkill")
    ResponseEntity addsecondkill(@RequestBody Seckill seckill){
        //后续从jwt中获取shopid
        seckill.setShopId(5);
        llService.addsecondkill(seckill);
        ResponseEntity result=new ResponseEntity<>("200","成功","");
        return result;
    }

    @RequestMapping("/addDiscountType")
    ResponseEntity addDiscountType(@RequestBody DiscountType discountType){
        //后续从jwt中获取shopid
        int goodsid = discountType.getShopId();
        discountType.setShopId(5);
        llService.addDiscountType(discountType,goodsid);
        ResponseEntity result=new ResponseEntity<>("200","成功","");
        return result;
    }
    @RequestMapping("/closeshop")
    ResponseEntity closeshop(){
        //从JWT中获取id
        llService.dayang(5);
        ResponseEntity result=new ResponseEntity<>("200","成功","");
        return result;
    }

    @RequestMapping("/openshop")
    ResponseEntity openshop(){
        //从JWT中获取id
        llService.openshop(5);
        ResponseEntity result=new ResponseEntity<>("200","成功","");
        return result;
    }
    @RequestMapping("/getshopstatus")
    ResponseEntity getshopstatus(){
        //JWT获取用户id
        Shop getshopstatus = llService.getshopstatus(1);
        if(getshopstatus.getStatus().equals("n")){
            ResponseEntity result=new ResponseEntity<>("202","成功","");
            return result;
        }else{
            ResponseEntity result=new ResponseEntity<>("201","成功","");
            return result;
        }
    }
}